﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// SessionManage 的摘要说明
/// </summary>
public class SessionManage
{
    public static bool IsUserLogIn
    {
        get
        {
            return !(User == null);
        }
    }

    #region 当前登录用户

    /// <summary>
    /// 当前登录用户
    /// </summary>
    public static UserInfo User
    {
        get
        {
            UserInfo ui = HttpContext.Current.Session["UserInfo"] as UserInfo;
            if (ui == null && HttpContext.Current.User.Identity.IsAuthenticated)
            {
                UserLogin(HttpContext.Current.User.Identity.Name);
                return HttpContext.Current.Session["UserInfo"] as UserInfo;
            }
            else
                return ui;
        }
        set
        {
            HttpContext.Current.Session["UserInfo"] = value;
        }
    }

    public static void UserLogin(string username)
    {
        UserInfo ui = new UserInfo();
        ui.PtAccount = username;
        SessionManage.User = ui;
    }

    #endregion

}
